package com.tianji.promotion.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class PromotionConfig {

    @Bean
    public ThreadPoolTaskExecutor generateExchangeCodeExecutor(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //核心线程大小，默认1 CPU
        executor.setCorePoolSize(20);
        //最大线程大小，默认是Ineger最大值
        executor.setMaxPoolSize(20);
        //等待队列大小，默认是Integer最大值
        executor.setQueueCapacity(999);
        //线程名称:方便问题排查
        executor.setThreadNamePrefix("discount-silution-calculator-");
        //拒绝策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        //线程初始化
        executor.initialize();
        return executor;
    }
}